//
//  String+Source.swift
//  SingWeibo
//
//  Created by shiying on 16/1/3.
//  Copyright © 2016年 shiying. All rights reserved.
//

import Foundation
extension String {
   
    func source() ->String? {
        // 创建正规表达示
        let regular = try! NSRegularExpression(pattern: ">(.*?)<", options: NSRegularExpressionOptions.DotMatchesLineSeparators)
    
        // 让正则表达式对象去匹配字符串 匹配第一个
        let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSRange(location: 0, length: self.characters.count))
        
        // 判断匹配结果的数量
        if result?.numberOfRanges > 1 {
            // 截取字符串
            let range = result!.rangeAtIndex(1)
            let re = (self as NSString).substringWithRange(range)
            return re
        } else {
            return nil
        }
    }
}
